/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework
 * Version 2.10
 * 
 * Validation Event Arguments Class
 *      Provides an event arguments definition for business object validation events.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;

namespace Adaptive.Foundation.Data
{
    /// <summary>
    /// Provides an event arguments definition for business object validation events.
    /// </summary>
    public class ValidationEventArgs : EventArgs
    {
        /*--------------------------------------------------------------------------------
		 * Private Member Declarations
		 *------------------------------------------------------------------------------*/
        #region Private Member Declarations
        /// <summary>
        /// Exception if one was caught.
        /// </summary>
        private Exception _ex;
        /// <summary>
        /// Validation message.
        /// </summary>
        private string _message;
        /// <summary>
        /// Not-serious warning idnicator.
        /// </summary>
        private bool _warningOnly;
        /// <summary>
        /// Validation success flag.
        /// </summary>
        private bool _success;
        /// <summary>
        /// Item to be referenced.
        /// </summary>
        private object _referenceItem;
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
		 *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public ValidationEventArgs()
        {
            _success = true;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="referenceItem">The object being validated or other reference data.</param>
        public ValidationEventArgs(object referenceItem)
        {
            _message = string.Empty;
            _success = true;
            _referenceItem = referenceItem;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="success">A value indicating whether the validation was successful.</param>
        public ValidationEventArgs(bool success)
        {
            _message = string.Empty;
            _success = success;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="success">A value indicating whether the validation was successful.</param>
        /// <param name="referenceItem">The object being validated or other reference data.</param>
        public ValidationEventArgs(bool success, object referenceItem)
        {
            _message = string.Empty;
            _success = success;
            _referenceItem = referenceItem;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="message">A validation message.</param>
        public ValidationEventArgs(string message)
        {
            _message = message;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="message">A validation message.</param>
        /// <param name="referenceItem">The object being validated or other reference data.</param>
        public ValidationEventArgs(string message, object referenceItem)
        {
            _message = message;
            _referenceItem = referenceItem;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="message">A validation message.</param>
        /// <param name="ex">The exception being caught.</param>
        public ValidationEventArgs(string message, Exception ex)
        {
            _ex = ex;
            _message = message;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="message">A validation message.</param>
        /// <param name="ex">The exception being caught.</param>
        /// <param name="referenceItem">The object being validated or other reference data.</param>
        public ValidationEventArgs(string message, Exception ex, object referenceItem)
        {
            _ex = ex;
            _message = message;
            _referenceItem = referenceItem;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="message">A validation message.</param>
        /// <param name="ex">The exception caught during validation.</param>
        /// <param name="warningOnly">A value indicating whether the validation is a warning-level only.</param>
        public ValidationEventArgs(string message, Exception ex, bool warningOnly)
        {
            _ex = ex;
            _message = message;
            _warningOnly = warningOnly;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="message">A validation message.</param>
        /// <param name="ex">The exception caught during validation.</param>
        /// <param name="warningOnly">A value indicating whether the validation is a warning-level only.</param>
        /// <param name="referenceItem">The object being validated or other reference data.</param>
        public ValidationEventArgs(string message, Exception ex, bool warningOnly, object referenceItem)
        {
            _ex = ex;
            _message = message;
            _warningOnly = warningOnly;
            _referenceItem = referenceItem;
        }
        /// <summary>
        /// Class destructor.
        /// </summary>
        ~ValidationEventArgs()
        {
            _ex = null;
            _message = null;
            _referenceItem = null;
        }
        #endregion

        /*--------------------------------------------------------------------------------
	     * Public Properties
		 *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets the reference to the exception caught during validation.
        /// </summary>
        /// <value>
        /// An <see cref="Exception"/> instance if one was caught; or <b>null</b>.
        /// </value>
        public Exception Exception
        {
            get { return _ex; }
        }
        /// <summary>
        /// Gets or sets the validation message for display or logging.
        /// </summary>
        /// <value>
        /// A validation message.
        /// </value>
        public string ValidationMessage
        {
            get { return _message; }
            set { _message = value; }
        }
        /// <summary>
        /// Gets the reference to the instance being validated.
        /// </summary>
        /// <value>
        /// A reference to the instance being validated, some other data container, or <b>null</b>.
        /// </value>
        public object ReferencedItem
        {
            get { return _referenceItem; }
        }
        /// <summary>
        /// Gets a value indicating whether the validation error is to be treated only as a warning.
        /// </summary>
        /// <value>
        /// <b>true</b> if the validation error is a warning; otherwise, <b>false</b>.
        /// </value>
        public bool WarningError
        {
            get { return _warningOnly; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the validation was successful.
        /// </summary>
        /// <value>
        /// <b>true</b> if the validation succeeded; otherwise, <b>false</b>.
        /// </value>
        public bool Success
        {
            get { return _success; }
            set { _success = value; }
        }
        #endregion
    }
}